﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Philip Stears 
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@connectbasic.net.
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

namespace ConnectBasic.Execution
{
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using Microsoft.Scripting;

    /// <summary>
    /// Provides an error sink which collects errors in a list.
    /// </summary>
    public class ListErrorSink : ErrorSink
    {
        private List<SyntaxErrorException> mList = new List<SyntaxErrorException>();
        private IList<SyntaxErrorException> mReadOnly;

        /// <summary>
        /// Initializes a new instance of the error sink.
        /// </summary>
        public ListErrorSink()
        {
            mReadOnly = new ReadOnlyCollection<SyntaxErrorException>(mList);
        }

        /// <summary>
        /// Returns a read-only list of errors.
        /// </summary>
        public IList<SyntaxErrorException> Errors
        {
            get { return mReadOnly; }
        }

        /// <inheritdoc />
        public override void Add(SourceUnit source, string message, SourceSpan span, int errorCode, Severity severity)
        {
            mList.Add(new SyntaxErrorException(message, source, span, errorCode, severity));
        }
    }
}
